package com.czy.owner.net.utils;

import android.app.Dialog;
import android.content.Context;
import android.widget.TextView;

import com.czy.owner.R;


/**
 * Created by wangyang on 2017/4/26.
 * 加载进度框
 */
public class MyLoadView {
    private Context mContext;
    private Dialog progressDialog;
    private TextView tvcontent;
    private String mLoadingTip;
    private boolean isCancelable;

    public MyLoadView(Context mContext, String str) {
        this.mContext = mContext;
        this.mLoadingTip = str;
        progressDialog = new Dialog(mContext, R.style.progress_dialog);
        progressDialog.setContentView(R.layout.dialog_loading);
        progressDialog.setCancelable(true);
        progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        tvcontent = (TextView) progressDialog.findViewById(R.id.tv_loadingmsg);
        tvcontent.setText(str);
    }

    public MyLoadView(Context mContext, String mLoadingTip, boolean isCancelable, boolean isTouch) {
        this.mContext = mContext;
        this.mLoadingTip = mLoadingTip;
        this.isCancelable = isCancelable;
        progressDialog = new Dialog(mContext, R.style.progress_dialog);
        progressDialog.setContentView(R.layout.dialog_loading);
        progressDialog.setCancelable(isCancelable);
        progressDialog.setCanceledOnTouchOutside(isTouch);
        progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        tvcontent = (TextView) progressDialog.findViewById(R.id.tv_loadingmsg);
        tvcontent.setText(mLoadingTip);
    }

    public void ShowLoadView() {
        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        } else {
            try {
                if (progressDialog != null && !progressDialog.isShowing()){
                    progressDialog.show();
                }
            }
            catch (Exception e){

            }


        }

    }

    public MyLoadView setContent(String content) {
        tvcontent.setText(content);
        return this;
    }

    public void CancleLoadView() {
        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    public boolean isShow() {
        if (progressDialog.isShowing()) {
            return true;
        } else {
            return false;
        }

    }
}
